// pages/fans/fans.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    notice:true,
    list: [],
    is_focus: 2,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (t) {
    getApp().page.onLoad(this, t),
    this.setData({
      is_focus: t.is_focus == 1 ? 1 : 2
    }), this.loadData(t);
    wx.setNavigationBarTitle({
      title: t.is_focus == 1 ? '关注' : '粉丝'
    })
  },
  loadData(t){
    var a = this;
    getApp().core.showLoading({
        title: "加载中"
    }), getApp().request({
        url: getApp().api.weitao.get_not_focus,
        data: {
          is_focus: a.data.is_focus
        },
        success: function(t) {
            0 == t.code && a.setData({
                list: t.data.list,
            });
        },
        complete: function() {
            getApp().core.hideLoading();
        }
    });
  },
  //跳转页面
  goUrl: function (e) {
    var gopage = e.currentTarget.dataset.url;
    if (!gopage) {
      return;
    }
    getApp().core.navigateTo({
      url: gopage
    });
  },
  /**
   * 
   * @param {*} e 
   * 关注
   */
  focus_action(e){
    var user = e.currentTarget.dataset.user,
    s=this;
    var like_data = 0;
    user.is_user_liked == 1? like_data=2 : like_data=1;
    if(user.user_id > 0){
      var a = this;
      getApp().core.showLoading({
          title: "加载中"
      }), getApp().request({
          url: getApp().api.weitao.focus_user,
          data: {
           user_id: s.data.is_focus == 1 ? user.focus_user : user.user_id,
           is_user_liked: like_data
          },
          success: function(t) {
              0 == t.code && (a.loadData());
              getApp().core.showToast({
                title: t.msg,
                icon: 0 == t.code ? 'success' : 'none'
              });
          },
          complete: function() {
              getApp().core.hideLoading();
          }
      });
    }else{
      getApp().core.showToast({
        title: "系统错误",
        icon: 'none'
      });
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})